$(()=>{
    // 点击获取验证码
    $('.btn1').on('click',function(){
        let url = wurl + '/user/sendVerify';
        let mobile = $('.mobile').val();
        if(!/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/.test(mobile)){
            layer.msg('手机号格式错误');
            return false;
        }

        let data = {mobile};
        $.get(url,data,function(response){
            if(response.code!=0){
                layer.msg(response.msg);
                return false;
            }
            $('.btn1').prop('disabled',true);
            let date = (+new Date())+60000;
            let timer = setInterval(()=>{
                let currentDate = +new Date();
                let showTime = Math.ceil((date - currentDate)/1000);
                $('.btn1').val(showTime+'s');
                if(showTime == 0){
                    $('.btn1').val('获取验证码');
                    $('.btn1').removeAttr('disabled');
                    clearInterval(timer);
                }

            },1000);
            console.log(response.data.verifyCode);
            // 倒计时验证码下次发出时间,一般就是一分钟
            
        });
    });
    
    // 点击注册
    $('.btn2').on('click',function(){
        let url = wurl + '/user/register';
        let mobile = $('.mobile').val();
        if(!/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/.test(mobile)){
            layer.msg('手机号格式错误');
            return false;
        }
        let password = $('.password').val();
        let verifyCode = $('.verifyCode').val();
        console.log(mobile,verifyCode,password);
        $.post(url,{mobile,verifyCode,password},function(response){
            if(response.code!=0){
                layer.msg(response.msg);
                return false;
            }
            // location.href = 'login.html';
        });
    });
});

